The Coronavirus Dashboard: the case of New Zealand
This Coronavirus dashboard: the case of New Zealand provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for New Zealand. This dashboard is built with R using the R Makrdown framework and with Flexadashboard.
Code
The code behind this dashboard is available on GitHub.
Data
The input data for this dashboard is the dataset available from the European Centre for Disease Prevention and Control
The data and dashboard are refreshed on a daily basis.
Some data is also pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository. But I find them late to update due to time zone differences.
Contact
For any question or feedback, you can email me mattbixley72@gmail.com or report an issue at the GitHub repo
Update
The data is as of Friday March 27, 2020 and the dashboard has been updated on Friday March 27, 2020 at 21:36.
---
title: "COVID19 - New Zealand"
author: "Matt Bixley"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
vertical_layout: fill
theme: bootstrap
#logo: images/coronavirus.png
---
```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
library(tidyverse)
library(lubridate)
library(ggthemes)
library(scales)
#theme_set(theme_wsj)
#theme_set(theme_bw)
#------------------ Parameters ------------------
# cases today
nzcases = 85
nzdeaths = 0
#------------------ Data ------------------
source("code/import_jhu.R")
source("code/insert_today.R")
#source("code/population.R")
# read the jhu set for the lat/long
jhu_confirmed <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
jhu <- read_csv(jhu_confirmed) %>%
rename(country = "Country/Region") %>%
map_df(str_replace_all, pattern = " ", replacement = "_") %>%
mutate(country = ifelse(country == "Taiwan*", "Taiwan",country)) %>%
mutate(country = ifelse(country == "Korea,_South", "South_Korea",country)) %>%
mutate(country = ifelse(country == "US", "United_States_of_America",country)) %>%
group_by(country) %>% # hack to get just one copy of country
mutate(first = rank(country)) %>%
filter(first == 1) %>%
select(country, Lat, Long)
# Import from the European CDC
ecdc_url <- "https://opendata.ecdc.europa.eu/covid19/casedistribution/csv/"
download.file(url = ecdc_url, destfile = "data/ecdc.csv")
covid19 <- read_csv("data/ecdc.csv") %>%
rename(date = "dateRep", country = "countriesAndTerritories", population = "popData2018") %>%
left_join(.,jhu) %>% # merge with jhu to get the lat long
mutate(date = dmy(date)) %>%
arrange(date, country) %>%
mutate(population = ifelse(country == "China", 58500000/0.83, population)) %>% #correct pop to reflect hubei
group_by(country) %>%
mutate(cum_cases = cumsum(cases)) %>%
mutate(cum_deaths = cumsum(deaths)) %>%
ungroup() %>%
mutate(country = ifelse(country == "United_States_of_America", "USA",country)) %>% # per capita
filter(country != "Cases_on_an_international_conveyance_Japan")
covid19 <- insert_today(cases = nzcases, deaths = nzdeaths)
covid19 <- covid19 %>%
mutate(per_million = round(cum_cases/population*1000000,1))
latest <- covid19 %>% filter(date == max(date))
nz <- covid19 %>% filter(country == "New_Zealand")
usa <- covid19 %>% filter(country == "USA")
italy <- covid19 %>% filter(country == "Italy")
```
Sidebar {.sidebar}
=====================================
{ width=100% }
Summary
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### confirmed {.value-box}
```{r}
#valueBox(value, subtitle, icon = NULL, color = "aqua", width = 4,href = NULL)
valueBox(
value = paste(format(max(nz$cum_cases), big.mark = ","), "", sep = " "),
caption = "Total confirmed cases",
icon = "fas fa-user-md",
color = "silver"
)
```
### active {.value-box}
```{r}
valueBox(
value = paste(format(max(nz$per_million), big.mark = ","), "", sep = " "),
caption = "Cases per million",
icon = "fas fa-user-md",
color = "silver"
)
```
### death {.value-box}
```{r}
valueBox(
value = paste(format(max(nz$cum_deaths), big.mark = ","), "", sep = " "),
caption = "Death cases (death rate)",
icon = "fas fa-user-md",
#color = ifelse(nz$cumulative_deaths > 0, "red", "silver")
color = "silver"
)
```
Row
-----------------------------------------------------------------------
### **Daily cumulative cases by type** (New Zealand only)
```{r}
# plot nz growth
#who <- "New Zealand"
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea")
p1 <- covid19 %>% filter(country %in% who, per_million > 5) %>%
group_by(country) %>%
mutate(days5 = dense_rank(date)) %>%
ungroup() %>%
#ggplot(aes(x = date, y =cum_cases , colour = country)) +
ggplot(aes(x = days5, y = per_million, colour = country)) +
geom_point() +
geom_line()
p1 + theme_wsj() + scale_colour_wsj()
```
Comparison
=======================================================================
Column {data-width=400}
-------------------------------------
### **Daily new cases**
```{r}
#----------------------------------------
# Plotting the data
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea")
p2 <- covid19 %>% filter(country %in% who , cum_cases > 0) %>%
group_by(country) %>%
mutate(days = dense_rank(date)) %>%
ungroup() %>%
ggplot(aes(x = days, y = cum_cases, colour = country)) +
geom_point() +
geom_line() +
scale_y_continuous(trans = "log10",
breaks = trans_breaks("log10",function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
p2 + theme_wsj(color = "gray") + scale_colour_wsj("colors6")
```
### **Daily Cases**
```{r}
who <- c("New_Zealand", "Australia", "USA", "Italy", "China", "South_Korea")
p3 <- covid19 %>% filter(cum_cases > 360) %>%
ggplot(aes(x = date, y = country, fill = cases)) +
geom_tile(colour = "lightgray") +
scale_fill_gradient(low = "orange", high = "orangered4")
p3 + theme_wsj(color = "gray", ) + scale_colour_wsj("colors6") +
theme(axis.text.y = element_text(size = 5))
```
Map
=======================================================================
### **World map of cases** (*use + and - icons to zoom in/out*)
```{r}
# make a map
#library(leaflet)
#library(leafpop)
#map_object %>%
# addLayersControl(
# overlayGroups = names(cv_data_for_plot.split),
# options = layersControlOptions(collapsed = FALSE)
# )
```
About
=======================================================================
**The Coronavirus Dashboard: the case of New Zealand**
This Coronavirus dashboard: the case of New Zealand provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic for New Zealand. This dashboard is built with R using the R Makrdown framework and with Flexadashboard.
**Code**
The code behind this dashboard is available on [GitHub](https://github.com/mattbixley/covid19){target="_blank"}.
**Data**
The input data for this dashboard is the dataset available from the
[{ width=3%}](https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide){target="_blank"} European Centre for Disease Prevention and Control
The data and dashboard are refreshed on a daily basis.
Some data is also pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/CSSEGISandData/COVID-19){target="_blank"}.
But I find them late to update due to time zone differences.
**Contact**
For any question or feedback, you can email me or report an issue at the [GitHub repo](https://github.com/MattBixley/COVID19/issues){target="_blank"}
**Update**
The data is as of `r format(max(covid19$date), "%A %B %d, %Y")` and the dashboard has been updated on `r format(Sys.time(), "%A %B %d, %Y")` at `r format(Sys.time(), "%H:%M")`.